using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;
using EntLibEC.Biz;
using EntLibEC.Biz.Basic;
using EntLibEC.Info.Basic;

namespace EntLibEC.View.Basic
{
	/// <summary>
	/// Summary description for SysPrivilegeSearch.
	/// </summary>
	public partial class SysPrivilegeSearch : PageBase
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			DataGrid1.PageSize = AppConst.PageSize;
			DataGrid1.PagerStyle.PageButtonCount = AppConst.PageButtonCount;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);

		}
		#endregion

		protected void btnSearch_Click(object sender, System.EventArgs e)
		{
			BindGrid();
		}

		private void BindGrid()
		{
			Hashtable ht = new Hashtable(5);
			if ( txtID.Text.Trim()!=AppConst.StringNull)
				ht.Add("privilegeid", txtID.Text.Trim());
			if ( txtName.Text.Trim() != AppConst.StringNull)
				ht.Add("privilegename", txtName.Text.Trim());

			DataSet ds = ConvertDs(SysManager.GetInstance().GetPrivilegeDs(ht));

			base.SetDataGridPage(ds, DataGrid1);

			DataGrid1.DataSource = ds;
			DataGrid1.DataBind();

			int rows = 0;
			if ( Util.HasMoreRow(ds) )
				rows = ds.Tables[0].Rows.Count;
			Assert(lblMessage, rows.ToString() + " record(s)", 1);

		}

		private DataSet ConvertDs(DataSet ds)
		{
			if ( !Util.HasMoreRow(ds))
				return ds;

			ds.Tables[0].Columns.Add("StatusName");

			foreach( DataRow dr in ds.Tables[0].Rows )
			{
				dr["StatusName"] = AppEnum.GetBiStatus(Int32.Parse(dr["Status"].ToString()));
			}
			return ds;
		}

		private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			DataGrid1.CurrentPageIndex = e.NewPageIndex;
			BindGrid();
		}

	}
}
